package com.cleaningcloud.cld.controller;

import com.cleaningcloud.cld.domain.CldDegreetitleResult;
import com.cleaningcloud.cld.domain.dto.CldDegreetitleDto;
import com.cleaningcloud.cld.service.ICldDegreetitleResultService;
import com.cleaningcloud.cld.service.ICldDegreetitleService;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 满意度结果Controller
 *
 * @author cleaningcloud
 * @date 2024-10-27
 */
@RestController
@RequestMapping("/result")
public class CldDegreetitleResultController extends BaseController {
    @Autowired
    private ICldDegreetitleResultService cldDegreetitleResultService;

    @Autowired
    private ICldDegreetitleService cldDegreetitleService;

    /**
     * 查询满意度结果列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CldDegreetitleResult cldDegreetitleResult) {
        startPage();
        List<CldDegreetitleResult> list = cldDegreetitleResultService.selectCldDegreetitleResultList(cldDegreetitleResult);
        return getDataTable(list);
    }

    @Operation(description = "调查问卷详情")
    @GetMapping("/selectSurveryDetails")
    public AjaxResult selectSurveryDetails(CldDegreetitleDto cldDegreetitleDto) {
        return success(cldDegreetitleService.selectSurveryDetails(cldDegreetitleDto));
    }

    /**
     * 导出满意度结果列表
     */
    @Log(title = "满意度结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CldDegreetitleResult cldDegreetitleResult) {
        List<CldDegreetitleResult> list = cldDegreetitleResultService.selectCldDegreetitleResultList(cldDegreetitleResult);
        ExcelUtil<CldDegreetitleResult> util = new ExcelUtil<CldDegreetitleResult>(CldDegreetitleResult.class);
        util.exportExcel(response, list, "满意度结果数据");
    }

    /**
     * 获取满意度结果详细信息
     */
    @GetMapping(value = "/{degreetitleResultId}")
    public AjaxResult getInfo(@PathVariable("degreetitleResultId") Long degreetitleResultId) {
        return success(cldDegreetitleResultService.selectCldDegreetitleResultByDegreetitleResultId(degreetitleResultId));
    }

    /**
     * 新增满意度结果
     */
    @Log(title = "满意度结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldDegreetitleResult cldDegreetitleResult) {
        return toAjax(cldDegreetitleResultService.insertCldDegreetitleResult(cldDegreetitleResult));
    }

    /**
     * 修改满意度结果
     */
    @Log(title = "满意度结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldDegreetitleResult cldDegreetitleResult) {
        return toAjax(cldDegreetitleResultService.updateCldDegreetitleResult(cldDegreetitleResult));
    }

    /**
     * 删除满意度结果
     */
    @Log(title = "满意度结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{degreetitleResultIds}")
    public AjaxResult remove(@PathVariable Long[] degreetitleResultIds) {
        return toAjax(cldDegreetitleResultService.deleteCldDegreetitleResultByDegreetitleResultIds(degreetitleResultIds));
    }
}
